package com.jboltai.event.chain;

import java.util.concurrent.ConcurrentHashMap;

public class ChainData {

    private ConcurrentHashMap data = new ConcurrentHashMap();

    /**
     * 获取数据
     * @param key
     * @return
     * @param <T>
     */
    public <T> T get(String key) {
        return (T) data.get(key);
    }


    /**
     * 绑定数据，key如果重复会覆盖
     * @param key
     * @param value
     */
    public void put(String key, Object value) {
        data.put(key, value);
    }

    /**
     * 如果key之前不存在，则绑定value
     * @param key
     * @param value
     */
    public boolean putIfAbsent(String key, Object value) {
        return data.putIfAbsent(key, value) == null;
    }

    /**
     * 移除数据
     * @param key
     */
    public void remove(String key) {
        data.remove(key);
    }

}
